



<?php
				

				
  function show_search($str_id,$type){
			$str_id=strval($str_id);
		$list=explode("|",$str_id);
		$list_id1=explode("@",substr($list[0],0));
		$list_id2=explode("@",substr($list[1],0));
  
			if($type==0){
				$table="official_list_name";
				$listname_id=$list_id1;
			}else{
				$table="user_list_name";
				$listname_id=$list_id2;
			}
			$page=isset($_POST['page'])?intval($_POST['page']):1;
			$num=10;
			$total=count($listname_id);
			$pagenum=ceil($total/$num);
			If($page>$pagenum || $page == 0){
				echo "error : Can Not Found The page .";
				exit;
			}
			if($total<$num){
			$num=$total;
			}
			$offset=($page-1)*$num;
			$end=$num*$page;

			
			for($i=$offset;$i<$end;$i++){
			$id=$listname_id[$i];
			$sql="select * from ".$table." where id='$id'";
			$results=mysql_query($sql);
			$rows=mysql_fetch_array($results);
				if($rows['user_id']==0){
				$user_name="游客";
				}else{
				
				$result=mysql_query("select * from userinf where id='".$rows['user_id']."'")or die(mysql_error());
				$row=mysql_fetch_array($result);
				$user_name=$row['username'];
				
				}
				if($type==0){
				?>
					<div class="pl_1">
						<div class="pic">
							<img src="<?php echo $rows['img_path']; ?>">
						</div>
						<div class="list_1_content">
							<?php echo "<a style='color:#444;font-size:23px;' href='MusicListContent.php?listname_id=$rows[id]&type=0&sort_id=$rows[list_sort_id]' onclick=add_browse_o($rows[id])>".$rows['list_name']."</a>";?><br/>
							<span style="color:#777;font-size:12px;">更新时间 : </span><span style="color:#777;font-size:12px;"> 每周一 12:30 a.m</span>
						</div>
					</div>
				<?php
				}else{?>
				<div class="pl_1">
							<div class="pic">
								<img style="width:48px;height:48px;"src="<?php echo $rows['img_path']; ?>">
							</div>
							<div class="list_1_content">
								<div class="list_name">
									<?php echo "<a style='color:#444;font-size:21px;' href='MusicListContent.php?listname_id=$rows[id]&type=1&sort_id=$rows[list_sort_id]' onclick='add_browse_u(".$rows['id'].")'>".$rows['list_name']."</a>";?><br/>
								</div>
								<div class="user_name">
									<span style="color:#777;font-size:12px;">发布时间 : </span><span style="color:#777;font-size:12px;"><?php echo $rows['create_time']; ?></span>
									<span class="un_useful_2">@:</span><a href="#" ><?php echo $user_name; ?></a>
								</div>
							</div>
				</div>				
				
			<?php	
				
				}
					}
			echo '<div class="feiye">';
			 fenyexianshi($page,$pagenum,$type,"search_fenye",$str_id,"-5","-5");////////////////逻辑分页、分块
			echo '</div>'; 
}
				
				

function search($get_str){
include("conn.php");
require_once("rep_spe_cha.php");
$str_id="";
$str=str_check($get_str);
if($str==""){
return false;
}
//$str="中国  福布斯";
$str=trim($get_str);
$key_space=explode(' ',$str);
$key=array_filter($key_space);
foreach($key as $p=>$v){
if($p==0){
//$keyword="keyword like '%$key[$p]%' ";
$keyword1="list_name like '%$key[$p]%' ";
$keyword2="mode_name like '%$key[$p]%' ";
$keyword3="content like '%$key[$p]%' ";
}else{
//$keyword=$keyword." and keyword like '%$key[$p]%' ";
$keyword1=$keyword1."and list_name like '%$key[$p]%' ";
$keyword2=$keyword2."and mode_name like '%$key[$p]%' ";
$keyword3=$keyword3."and content like '%$key[$p]%' ";

}

}

//官方搜索
 for($k=0;$k<2;$k++){			//官方和用户

		if($k==0){
		$list="official_list_name";
		$mode="official_list_mode";
		$content="official_list_content";
		}else if($k==1){
		$list="user_list_name";
		$mode="user_list_mode";
		$content="user_list_content";
		}

//list查询
		$sql="select * from ".$list." where ".$keyword1;
		$result=mysql_query($sql)or die("数据库查询失败:".mysql_error());
		while($rows=mysql_fetch_array($result)){
		//echo $rows['id']."<br/>";
		$list_name_id[]=$rows['id'];
		}
//mode查询
		$sql="select * from ".$mode." where ".$keyword2;
		$result=mysql_query($sql)or die("数据库查询失败:".mysql_error());
		while($rows=mysql_fetch_array($result)){
		//echo $rows['name_id']."<br/>";

			$list_name_id[]=$rows['name_id'];

		}

//content查询
		$sql="select * from ".$content." where ".$keyword3;
		$result=mysql_query($sql)or die("数据库查询失败:".mysql_error());
		while($rows=mysql_fetch_array($result)){
					$list_name_id[]=$rows['list_name_id'];		
		}

		
		
		
		
if(empty($list_name_id)){ 
	//echo "对不起!木有找到与<font color='red'>“".$get_str."”</font>相关榜单";
	return false;

}

//关键词的搜索和记录
$sq="select * from hot_keyword  where keyword='$str'";
$resul=mysql_query($sq)or die(mysql_error());
	
	if($roww=mysql_fetch_row($resul)){
	$count=$roww[2]+1;
		$sl="update hot_keyword set count='$count' where id='$roww[0]'";
		$re=mysql_query($sl) or die(mysql_error());
	}else{
	
			$sll="insert hot_keyword (keyword) values ('$str')";
			$rel=mysql_query($sll) or die(mysql_error());
		
			if(count($key)!=1){
				foreach($key as $pp=>$vv){
				$sqq="select * from hot_keyword  where keyword ='$key[$pp]'";
				$resull=mysql_query($sqq)or die(mysql_error());
					if(!$rows=mysql_fetch_row($resull)){
						$sl="insert hot_keyword (keyword) values ('$key[$pp]')";
						$re=mysql_query($sl) or die(mysql_error());
					}
				}
			}
	}

//去重复listid
		for($id=0;$id<count($list_name_id);$id++){
		
		//echo $list_name_id[$id]."--";
			if($id==0){
				$listname_id[]=$list_name_id[$id];
				$str_id.=substr($list_name_id[$id],0);
			}else{

			for($j=0;$j<count($listname_id);$j++){
				if($listname_id[$j]==$list_name_id[$id]){
				break;
				}
			}
			if($j==count($listname_id)){
			$listname_id[]=$list_name_id[$id];
			$str_id.="@".substr($list_name_id[$id],0);
			}

			}

		//echo count($listname_id)."<br/>";	
			$j=0;
		 
		
}
$str_id.="|";
}

return $str_id;
}


?>